package com.onenine.app.adapter;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.onenine.app.R;
import com.onenine.app.model.GameCategory;
import com.onenine.app.utils.CHelper;
import com.onenine.common.util.ApUtils;
import com.onenine.common.util.ScreenUtils;
import com.onenine.glide.GlideApp;

import java.util.List;

public class GameCategoryAdapter extends BaseQuickAdapter<GameCategory, BaseViewHolder> {

    private Resources mResources;
    private int mItemWidth;

    public GameCategoryAdapter(@Nullable List<GameCategory> data) {
        super(R.layout.layout_chat_game_category_item, data);
        mResources = ApUtils.getApp().getResources();
        mItemWidth = ScreenUtils.getScreenWidth() / 3;
    }

    @Override
    protected void convert(BaseViewHolder helper, GameCategory item) {
        helper.setText(R.id.tv_name, item.getGameName());
        ImageView imageView = helper.getView(R.id.rb_image);
        ViewGroup.LayoutParams layoutParams = helper.getConvertView().getLayoutParams();
        layoutParams.width = mItemWidth;
        int iconSize = mResources.getDimensionPixelSize(R.dimen.game_item_icon_size);
        GlideApp.with(ApUtils.getApp()).load(CHelper.getOssThumbImageUrl(item.getGameIcon(), iconSize)).into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                imageView.setImageDrawable(resource);
            }
        });
    }
}
